<template>
  <div>
    <van-swipe
      class="my-swipe"
      :autoplay="autoplay"
      :duration="duration"
      :show-indicators="showIndicators"
      :indicator-color="indicatorColor"
      :height="height"
      :loop="IsLoop"
      :vertical="IsVertical"
      :touchable="IsTouchable"
      :stop-propagation="IsStopPropagation"
      @change="onChange"
    >
      <van-swipe-item
        v-for="(image, index) in images"
        :key="index"
        @click="ClickItem"
      >
        <img v-lazy="image" />
      </van-swipe-item>
    </van-swipe>
  </div>
</template>

<script>
import { Swipe, SwipeItem } from 'vant';
// 轮播图、页面切换组件
export default {
  name: 'commonSwipe',
  components:{
    'van-swipe':Swipe,
    'van-swipe-item':SwipeItem
  },
  props: {
    // 轮播的默认间隔
    autoplay: {
      type: Number,
      default: 3000
    },
    // 动画时长 单位ms
    duration: {
      type: Number,
      default: 1000
    },
    // 是否显示指示器
    showIndicators: {
      type: Boolean,
      default: true
    },
    // 指示器的颜色
    indicatorColor: {
      type: String,
      default: '#1989fa'
    },
    // 滑块的高度
    height: {
      type: Number,
      default: 200
    },
    // 是否循环播放
    IsLoop: {
      type: Boolean,
      default: true
    },
    // 是否纵向轮播
    IsVertical: {
      type: Boolean,
      default: false
    },
    // 是否可以通过手势滑动
    IsTouchable: {
      type: Boolean,
      default: true
    },
    // 是否阻止滑动事件冒泡
    IsStopPropagation: {
      type: Boolean,
      default: true
    },
    // 轮播的图片
    images: {
      type: Array,
      default: () => [
        'https://img01.yzcdn.cn/vant/apple-1.jpg',
        'https://img01.yzcdn.cn/vant/apple-2.jpg',
        'https://img01.yzcdn.cn/vant/apple-1.jpg',
        'https://img01.yzcdn.cn/vant/apple-2.jpg'
      ]
    }
  },
  data() {
    return {}
  },
  methods: {
    // swipe 的 change 事件
    onChange(index) {
      this.$emit('OnChange', index)
    },
    // swipe item 的 click 事件
    ClickItem(event) {
      this.$emit('Click', event)
    }
  }
}
</script>

<style lang="less" scoped>
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 300px;
  text-align: center;
  background-color: #39a9ed;
  img {
    width: 100%;
    height: 100%;
  }
}
/deep/ .van-swipe__indicator {
  background-color: #13171c;
}
</style>
